﻿using System;
using System.Collections.Generic;
using System.Text;
using MS.Core.Base.Data;
using System.Data;
using System.Data.Common;
using LHS.Core.TableInfo.SetUpCaseRecordForm;
using MS.Core.Constants;
using LHS.Core.TableInfo;

namespace LHS.Core.CaseRecord.DataCommons
{
    public class CommonCaseRecord_Category : DBBaseData
    {
        public DataTable getCaseRecord_CategoryDT(String strCategoryID)
        {
            DataTable dtReturn;
            try
            {
                String strSQL = "SELECT " + CaseRecord_CategoryInfo.TABLENAME + ".*, " + Convert.ToInt32(GlobalEnumType.Status.HAVE_VALUE).ToString() + " AS " + DBBaseInfo.Hidden_Status;
                strSQL += ", " + InfoSurgical.SURNAME + " AS " + CaseRecord_CategoryInfo.HIDDEN_NAME;
                strSQL += " FROM " + CaseRecord_CategoryInfo.TABLENAME;
                //strSQL += " Left JOIN " + InfoSurgical.TABLENAME; -- before
                strSQL += " Left JOIN " + InfoSurgical.TABLENAME; // thaoht edit here; boi vì, tien căn xét mặc định là ID = -9999, và không tôn tại thực sự trong bảng surgical
                strSQL += " ON " + CaseRecord_CategoryInfo.TABLENAME + "." + CaseRecord_CategoryInfo.CRC_ID + " = " + InfoSurgical.TABLENAME + "." + InfoSurgical.SURISN;
                if (strCategoryID != "")
                {
                    strSQL += " WHERE " + CaseRecord_CategoryInfo.TABLENAME + "." + CaseRecord_CategoryInfo.CRC_ID + " = '" + strCategoryID + "'";
                }
                DbCommand cmd = base.GetDbCommand(CommandType.Text, strSQL);
                dtReturn = base.GetData(cmd, CaseRecord_CategoryInfo.TABLENAME);
                if (dtReturn == null)
                    dtReturn = CaseRecord_CategoryInfo.GetStructure();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dtReturn;
        }

        public DataTable getSurgicalDT()
        {
            DataTable dtReturn;
            try
            {
                String strSQL = "SELECT * FROM " + InfoSurgical.TABLENAME;
                strSQL += " ORDER BY " + InfoSurgical.SURNAME;
                DbCommand cmd = base.GetDbCommand(CommandType.Text, strSQL);
                dtReturn = base.GetData(cmd, InfoSurgical.TABLENAME);
                if (dtReturn == null)
                    dtReturn = InfoSurgical.GetStructure();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dtReturn;
        }
    }
}